import React from "react";
import {
	Form,
	Input,
	Button,
	Dialog,
	TextArea,
	DatePicker,
	Selector,
	Slider,
	Stepper,
} from "antd-mobile";
import dayjs from "dayjs";
export default function MyForm({ onFinish, footer, options }: any) {
	return (
		<div>
			<Form onFinish={onFinish} footer={footer}>
				{options.map((item: any) => {
					if (item.type == "input") {
						return (
							<Form.Item
								name={item.name}
								label={item.label}
								rules={item.rules}
							>
								<Input {...item.children} />
							</Form.Item>
						);
					} else if (item.type == "date") {
						return (
							<Form.Item
								name={item.name}
								label={item.label}
								trigger={item.trigger}
								onClick={item.onClick}
							>
								<DatePicker {...item.children}>
									{value =>
										value
											? dayjs(value).format("YYYY-MM-DD")
											: "请选择日期"
									}
								</DatePicker>
							</Form.Item>
						);
					} else if (item.type == "select") {
						return (
							<Form.Item name={item.name} label={item.label}>
								<Selector {...item.children} />
							</Form.Item>
						);
					}
				})}
				{/* <Form.Item
					name="姓名"
					label="姓名"
					rules={[{ required: true, message: "姓名不能为空" }]}
				>
					<Input placeholder="请输入姓名" />
				</Form.Item>
				<Form.Item name="address" label="地址">
					<Input placeholder="请输入地址" />
				</Form.Item>
				<Form.Item
					name="birthday"
					label="生日"
					trigger="onConfirm"
					onClick={() => {
						setPickerVisible(true);
					}}
				>
					<DatePicker
						visible={pickerVisible}
						onClose={() => {
							setPickerVisible(false);
						}}
					>
						{value =>
							value
								? dayjs(value).format("YYYY-MM-DD")
								: "请选择日期"
						}
					</DatePicker>
				</Form.Item>
				<Form.Item name="favoriteFruits" label="喜爱的水果">
					<Selector
						columns={3}
						multiple
						options={[
							{ label: "苹果", value: "apple" },
							{ label: "橘子", value: "orange" },
							{ label: "香蕉", value: "banana" },
						]}
					/>
				</Form.Item> */}
			</Form>
		</div>
	);
}
